/**
 *  *2010-7-11 下午03:58:12  add 
 */
package com.base.myproject.client.busi.system;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.StoreInfo;
import com.base.myproject.client.ui.BaseGrid;
import com.base.myproject.client.ui.BaseGridPanel;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;

/**
 * @author Administrator
 *2010-7-11
 * javazgw@gmail.com
 */
public class SystemInfoPanelSimple extends BaseJDBCPanel{
	
	public SystemInfoPanelSimple()
	{
		init();
	}
	public void init()
	{
		initWidgetx();
	}

	
	private void initWidgetx() {
		
		add(createGrid());
	}


	BaseStore<BusiObject> store = null;
	BaseStore<BusiObject> getStore(){
	if(store==null) 
	{
		createStore();
	}
	return store;}
	BaseStore<BusiObject> createStore(){
	ModelType type = new ModelType();
	type.setRoot("records");
	type.setRecordName("record");
	type.setTotalName("totle");
	type.addField("icode");
	type.getField("icode").setType(Long.class);
	type.addField("id");
	type.getField("id").setType(String.class);
	type.addField("name");
	type.getField("name").setType(String.class);
	type.addField("tel");
	type.getField("tel").setType(String.class);
	StoreInfo info = new StoreInfo();
	info.setTablename("null");
	info.setKeyname(new String[] { "icode"});
	info.setSql("select icode,id,name,tel from systeminfo");
	//info.setParent(mainstore);// 关联主表
	//info.setLinkparentcolumns(new String[] { "icode" }); // 关联主表字段
	//info.setLinkparent_chile_columns(new String[] { "upicode" });// 关联主表字段
	  store = new BaseStore<BusiObject>(type, info);
	 return store;}
	
	

	BaseGridPanel grid=null;
	BaseGridPanel createGrid(){
	CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
	List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
	columns.add(cbs.getColumn());

//	ColumnConfig C1 = new ColumnConfig("icode", "icode", 80);
//	columns.add(C1);
	ColumnConfig C2 = new ColumnConfig("id", "id号", 80);
	TextField<String> c1t = new TextField<String>();
	C2.setEditor(new CellEditor(c1t));
	
	columns.add(C2);
	ColumnConfig C3 = new ColumnConfig("name", "部门名称", 200);
	TextField<String> c3t = new TextField<String>();
	C3.setEditor(new CellEditor(c3t));
	columns.add(C3);
	
	
	ColumnConfig C4 = new ColumnConfig("tel", "电话", 200);
	TextField<String> c4t = new TextField<String>();
	C4.setEditor(new CellEditor(c4t));
	columns.add(C4);

	ColumnModel cm = new ColumnModel(columns);
	grid = new BaseGridPanel(getStore(), cm);
	cbs.setSelectionMode(SelectionMode.SINGLE);
	grid.getBg().setSelectionModel(cbs);
	grid.getBg().setHeight(400);
	return grid ;}
}
